package week04.homework02ShapeCalculator.shape;

/**
 * @author li
 */
public class Triangle extends BaseShape {

    private double a;

    private double b;

    private double c;

    public Triangle(double a, double b, double c) {
        if (!isTriangle(a, b, c)) {
            throw new IllegalArgumentException("Invalid triangle sides");
        }
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public double getA() {
        return a;
    }

    public void setA(double a) {
        this.a = a;
    }

    public double getB() {
        return b;
    }

    public void setB(double b) {
        this.b = b;
    }

    public double getC() {
        return c;
    }

    public void setC(double c) {
        this.c = c;
    }

    @Override
    public double getArea() {
        double p = (a + b + c) / 2;
        return Math.sqrt(p * (p - a) * (p - b) * (p - c));
    }

    private boolean isTriangle(double a, double b, double c) {
        return a + b > c && a + c > b && b + c > a;
    }

}
